The library function loads the package and makes anything exported from the package directly available
## L u v col
## 1 9341.570 -3.370649e-12 0.0000 white
## 2 9100.962 -4.749170e+02 -635.3502 aliceblue
## 3 8809.518 1.008865e+03 1668.0042 antiquewhite
## 4 8935.225 1.065698e+03 1674.5948 antiquewhite1
## 5 8452.499 1.014911e+03 1609.5923 antiquewhite2
## 6 7498.378 9.029892e+02 1401.7026 antiquewhite3
Unpack the box and put all the items on the table
## L u v col
## 1 9341.570 -3.370649e-12 0.0000 white
## 2 9100.962 -4.749170e+02 -635.3502 aliceblue
## 3 8809.518 1.008865e+03 1668.0042 antiquewhite
## 4 8935.225 1.065698e+03 1674.5948 antiquewhite1
## 5 8452.499 1.014911e+03 1609.5923 antiquewhite2
## 6 7498.378 9.029892e+02 1401.7026 antiquewhite3
Only take a specific item out of the box, use it, then put it back
An R package could really be uploaded anywhere, but at least CRAN and Bioconductor don’t let anything through.
library needs to be called for every new session##
## Attaching package: 'dplyr'
## The following object is masked from 'package:ggplot2':
##
## vars
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
The function that was imported last takes precedence. To access other functions, use <package>::<function>.
## function (x, y, ...)
## UseMethod("intersect")
## <bytecode: 0x7fb9bcf4ee70>
## <environment: namespace:generics>
## function (x, y)
## {
## y <- as.vector(y)
## unique(y[match(as.vector(x), y, 0L)])
## }
## <bytecode: 0x7fb9b96bb6f0>
## <environment: namespace:base>
The conflicted package can help us avoid mistakes
## Error: [conflicted] `filter` found in 2 packages.
## Either pick the one you want with `::`
## * dplyr::filter
## * stats::filter
## Or declare a preference with `conflict_prefer()`
## * conflict_prefer("filter", "dplyr")
## * conflict_prefer("filter", "stats")
We can then resolve the conflict for the rest of our session
## [conflicted] Will prefer dplyr::filter over any other package
## function (.data, ..., .preserve = FALSE)
## {
## UseMethod("filter")
## }
## <bytecode: 0x7f9c99ae9f58>
## <environment: namespace:dplyr>
RStudio is an excellent tool for developing R packages, and helps out with a lot of the formalities
Not a part of this course though, but check out the book R Packages if you are interested